package org.axed.user.client.impl;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.core.client.GWT;

/**
 * Unfortunally Mozilla has some spezial ideas about
 * keyrepeat logic, which needs to be handled here.
 */
public class InputCatcherImplMoz extends InputCatcherImpl {
	/**
	 * Gets the mozilla specific extension charCode.
	 */
	private native int _getCharCode(Event event) /*-{
		return event.charCode;
	}-*/;

	/**
	 * TODO
	 */
	public int onKeyEvent(Event event) {
		int type = DOM.eventGetType(event);
		int keycode = DOM.eventGetKeyCode(event);
		int charcode = _getCharCode(event);

		switch (type) {
		case Event.ONKEYDOWN:
			return 0;
		case Event.ONKEYPRESS:
			if (keycode < 0) {
				// for example [altgr]
				return 0;
			}
			if (charcode != 0) {
				return charcode;
			}
			return -keycode;
		case Event.ONKEYUP:
			return 0;
		default:
			assert false;
			return 0;
		}
	}
}
